#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>

void clear(char *p)
{   
    int x,y;
    long int location = 0;
    for (y = 0; y < 320; y++)
        for (x = 0; x < 240; x++) 
        {
                location = x * 2 + y * 480;
                *((unsigned short *)(p + location)) =0xffff;
               }
}

void display(int x,int y,char hanzi[2][16],char *p)
{  
    int i, j,k,m;
    char tem;
    m=0;
    long int location = 0; 
    for(i=0;i<2;i++)
     { for(j=0;j<16;j++)
	{ 
	  tem=128;    		 
	  for(k=0;k<8;k++)
             { 
               if((hanzi[i][j] & tem) >0)                    
                   {location = x * 2 + y * 480;
                    *((unsigned short *)(p + location)) =0x0000;}
                   tem =tem >>1;
                   x=x+1;
                   m++;
                  if(m==16)
                      {x=x-16;y=y+1;m=0;}                       
             }
	}
      }  
               
}

int main(void)
{
        int fh;      
        long int screensize = 153600;
        char  *map=0;      
        char jiang[2][16] =
{{0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40,0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40},{0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00}};
char xi[2][16]={{0x00,0x00,0xFF,0xFE,0x04,0x40,0x04,0x40,0x7F,0xFC,0x44,0x44,0x44,0x44,0x44,0x44},{0x44,0x44,0x48,0x3C,0x50,0x04,0x60,0x04,0x40,0x04,0x7F,0xFC,0x40,0x04,0x00,0x00}};
char li[2][16]={{0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC},{0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40,0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00}};

char gong[2][16]={{0x00,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00},{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00}};
char da[2][16]={{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80},{0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04}};
char xue[2][16]={{0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40},{0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00}};
    if ((fh = open("/dev/fb0", O_RDWR)) == -1)
       {
        printf("error open %s: \n", "/dev/fb0");
	exit(1); 
        }
  /*printf("succeed open %s: \n", "/dev/fb0");*/
  map = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,fh,0);
    if ((int)map == -1) 
      {
        printf("Error: failed to map framebuffer device to memory.\n");
        exit(1);
       }
    /* printf("succeed map framebuffer device %s: \n", "/dev/fb0");*/
      clear(map);
      display(120,30,jiang,map);
      display(120,56,xi,map);
      display(120,82,li,map);
      display(120,108,gong,map);
      display(120,134,da,map);
      display(120,160,xue,map);
    munmap(map, screensize);
    close(fh);
    return 0;
}


